#pragma once

#include <yaml-cpp/yaml.h>
#include <string>
#include <memory>
#include <unordered_map>

class ConfigManager {
public:
    static ConfigManager& getInstance();
    
    // 初始化配置管理器
    bool init(const std::string& env = "default");
    
    // 获取配置项
    template<typename T>
    T get(const std::string& key, const T& defaultValue = T()) const;
    
    // 获取子配置节点
    YAML::Node getNode(const std::string& key) const;
    
    // 获取完整配置
    const AppConfig& getConfig() const { return appConfig_; }
    
    // 获取各个子配置
    const CameraConfig& getCameraConfig() const { return appConfig_.camera; }
    const NetworkConfig& getNetworkConfig() const { return appConfig_.network; }
    const InferenceConfig& getInferenceConfig() const { return appConfig_.inference; }
    const DisplayConfig& getDisplayConfig() const { return appConfig_.display; }
    const LogConfig& getLogConfig() const { return appConfig_.log; }

private:
    ConfigManager() = default;
    ~ConfigManager() = default;
    ConfigManager(const ConfigManager&) = delete;
    ConfigManager& operator=(const ConfigManager&) = delete;

    bool loadConfig(const std::string& filename);
    std::string resolveKey(const std::string& key) const;

    YAML::Node config_;
    std::string configDir_{"config"};

    void parseConfig();
    AppConfig appConfig_;
}; 